<?php
	
    define('IN_PHPBB', true);
	
     /** CONFIGURATION ***/
    $shared_key="CHANGE_THAT_OR_IT_WILL_NOT_WORK";
    $phpbb_root_path = './';     //Path to forum filesystem	
    $phpbb_url="/forum/";
	
    /** NO MORE CONFIG ***/


    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);
     
    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();

    if($user->data['is_registered'])
    {
         header("Location: ".$phpbb_url);
    }
    else
    {        
		$username=$_GET["username"];
		$key=$_GET["key"];		
		if(md5($username.$shared_key)!=$key) die("Shared Login failed");		
		
		$email=md5($username)."@dummyhost.com";
        $password=md5($shared_key.$username);
		$autologin = true;
		
        $result = $auth->login($username, $password, $autologin);

        if ($result['status'] == LOGIN_SUCCESS)
        {
            header("Location: ".$phpbb_url);
        }
        else
        {
           // Try Create user
		     include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
             include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
			 $user->session_begin();
             $auth->acl($user->data);
             $user->setup('ucp');		
			 
			
				$user_row = array(
                   'username'            => $username,
                   'user_password'         => phpbb_hash($password),
                   'user_email'         => $email,
                   'group_id'            => (int) 1,
                   'user_timezone'         => (float) 1,
                   'user_dst'            => $is_dst,
                   'user_lang'            => 'en',
                   'user_type'            => USER_NORMAL,
                   'user_actkey'         =>  gen_rand_string(10),
                   'user_ip'            => "192.168.178.1",
                   'user_regdate'         => time(),
                   'user_inactive_reason'   => $user_inactive_reason,
                   'user_inactive_time'   => $user_inactive_time,
                );

                // Register user...
                $user_id = user_add($user_row, $cp_data);
				$result = $auth->login($username, $password, $autologin);
				if ($result['status'] == LOGIN_SUCCESS)
					{
						header("Location: ".$phpbb_url);
					} else {
					die("Failure within phpBB System");
					}
        }
    }    
?> 